﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Zzva.Common
{
    public class CommonDateTime 
    {
        public static string GetShortDateIso(DateTime Ddate)
            {
                try
                {
                    string ShortDateIso;
                    string Yyear;
                    string Mmonth;
                    string Dday;


                    Yyear = Ddate.Year.ToString();
                    if (Yyear.Length != 4)  {throw (new CommonException("Нет такого года")); }

                    Mmonth = Ddate.Month.ToString();
                    if (Mmonth.Length == 2){}
                    else if (Mmonth.Length == 1){Mmonth = "0" + Mmonth;}
                    else {throw (new CommonException("Нет такого месяца")); }


                    Dday = Ddate.Day.ToString();
                    if (Dday.Length == 2) { }
                    else if (Dday.Length == 1) { Dday = "0" + Dday; }
                    else { throw (new CommonException("Нет такого дня")); }


                    ShortDateIso = Yyear + Mmonth + Dday;  

                    return ShortDateIso;

                }

                catch (Exception e) { throw e; }
                finally { }

            }

    }
}
